﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure
{
    public class DbContext
    {
        public SqlSugarClient Db { get; set; }

        public DbContext() 
        {
            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = "server=localhost;database=sqlsugger;uid=root;pwd=123456",
                DbType = DbType.MySql,
                IsAutoCloseConnection = true
            });

            // 自动创建数据库（如已存在会自动跳过）
            Db.DbMaintenance.CreateDatabase("测试1");

            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine($"SQL: {sql}");
            };
        }

    



        // 打印SQL到控制台（仅在调试时使用）
        
}
}
